Mohcine Madkour
Published

Sat 01 May 2021

←Home

How I achieved 97 % Accuracy in Covid-19 Diagnosis from classifying Chest X-ays Images

The COVID-19 pandemic continues to have a devastating effect on the health and well-being of the global population. Acritical step in the fight against COVID-19 is effective screening of infected patients, with one of the key screening approachesbeing radiology examination using chest radiography. In this study we introduce COVID-Net, a deep convolutional neural network design tailoredfor the detection of COVID-19 cases from chest X-ray (CXR) images that is open source and available to the general public.

What is a chest x-ray?

X-rays are a form of radiation like light or radio waves. X-rays pass through most objects, including the body, an x-ray machine produces a small burst of radiation that passes through the body, recording an image on photographic film or a special detector. On a chest x-ray, the ribs and spine will absorb much of the radiation and appear white or light gray on the image. Lung tissue absorbs little radiation and will appear dark on the image. X-rays based Covid19 Screening

ct-scan illustration
Illustration of x-rays taking bed

There are several advantages to leveraging CXR imaging for COVID-19 screening amid the global COVID-19 pandemic,particularly in resource-constrained areas and heavily-affected areas: - Rapid triaging: CXR imaging enables rapid triaging of patients suspected of COVID-19 and can be done in parallel of viral testing (which takes time) to help relief the high volumes of patients especially in areas most affected where theyhave ran out of capacity (e.g., New York, Spain, and Italy), or even as standalone when viral testing isn’t an option (lowsupplies). Furthermore, CXR imaging can be quite effective for triaging in geographic areas where patients are instructedto stay home until the onset of advanced symptoms (e.g., New York City), since abnormalities are often seen at time ofpresentation when patients suspected of COVID-19 arrive at clinical sites. - Availability and Accessibility: CXR imaging is readily available and accessible in many clinical sites and imagingcenters as it is considered standard equipment in most healthcare systems. In particular, CXR imaging is much morereadily available than CT imaging, especially in developing countries where CT scanners are cost prohibitive due to highequipment and maintenance costs. - Portability: The existence of portable CXR systems means that imaging can be performed within an isolation room,thus significantly reducing the risk of COVID-19 transmission during transport to fixed systems such as CT scanners aswell as within the rooms housing the fixed imaging systems.

As such, radiography examination can be conducted faster and have greater availability given the prevalence of chestradiology imaging systems in modern healthcare systems and the availability of portable units, making them a good complement to RT-PCR testing particularly since CXR imaging is often performed as part of standard procedure for patients with a respiratory complaint11. Furthermore, some have suggested that as the COVID-19 pandemic progresses, there will be a greater reliance on portable CXR due to the aforementioned advantages. However, one of the biggest bottlenecks faced is the need

Why X-rays?

There have been promising efforts to apply machine learning to aid in the diagnosis of COVID-19 based on CT scans. Despite the success of these methods, the fact remains that COVID-19 is an infection that is likely to be experienced by communities of all sizes. X-rays are inexpensive and quick to perform; therefore, they are more accessible to healthcare providers working in smaller and/or remote regions. Any insights that may be derived as a result of explainability algorithms applied to a successful model will be invaluable to the global effort of identifying and treating cases of COVID-19. This model is a prototype system and not for medical use and does not offer a diagnosis.

Data

I used Kaggle environment for completing my experiment, it is a good medium to replicate the result, at the references part of the article, you will find the link to the notebook.

Our data is represented by training and testing sets, the training consists of a total of a total of 5133 images, 3418 Pneumona images, 1266 Normal images, and 460 COVID19 images, and the testing set consists of 1288 images.

ct-scan illustration
Examples of X-rays images after data augmentation

The images in their raw format come in different sizes, I convert all the images through the image generator to the target_size of (300,300)

I use the generator to transform the values in each batch so that their mean is 0 and their standard deviation is 1. This will facilitate model training by standardizing the input distribution. I also converts the single channel X-ray images (gray-scale) to a three-channel format by repeating the values in the image across all channels. We will want this because the pre-trained model that I’ll use requires three-channel inputs

After the standardization and augmentation, I got the following images

Training method

I load the DenseNet169 model and I make the layers to Freeze Weights. I also add Full Connected Layers and dropouts to avoid Overfit. Data and Notebook : https://github.com/mohcinemadkour/Covid_CXR_Classifictaion

ct-scan illustration
DenseNet169 architecture

DenseNet architecture is new, it is a logical extension of ResNet. ResNet architecture has a fundamental building block (Identity) where you merge (additive) a previous layer into a future layer. Reasoning here is by adding additive merges we are forcing the network to learn residuals (errors i.e. diff between some previous layer and current one). In contrast, DenseNet paper proposes concatenating outputs from the previous layers instead of using the summation.

ct-scan illustration
A 5-layer dense block with a growth rate ofk= 4.Each layer takes all preceding feature-maps as input

Evaluating Model Accuarcy

ct-scan illustration
Some examples of classification results

I trained the model for a more than 6 hours on GeForce GTX 1060, Memory 5968MiB. The final model evaluation on the testing set is [0.06362051516771317, 0.9704968929290771]

I visualize the changes in model accuracy and loss during the training process, as this gives us important information to evaluate what we can do to improve accuracy.

ct-scan illustration
Some examples of classification results

Predictions from testing set

  • Out of 116 images in the first class ( Normal) the model was successful in identifying 13 of those correctly
  • Out of 312 imaged in the second class ( Pneumonia) the model was successful in identifying 74 of those correctly
  • Out of 857 points in the third class (Covid19) the model was successful in identifying 582 of those correctly
ct-scan illustration
Learning curves: Accuracy and loss plots

This gives as output an accuracy of 97%, which is not bad! But, can we do better? We have a limited amount of data, so how about trying to improve that using image augmentation? Some reseaches indicate that with some augmentation effort a significant increase in prediction accuracy can be obtained when small data sets are considered. I am planing to try different augmentation techiques to my original data set in order to increase the accuracy. I am also trying to reduce the false positive and false negative in classifying COVID images. I am planing to report on that on my future blogs.

Acknowledgements

Images are collected from various publicly available resources. If you use the data for research please give credit to authors: Sources:

  • https://github.com/ieee8023/covid-chestxray-dataset
  • https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia
  • https://github.com/agchung

References

  • https://towardsdatascience.com/calibration-techniques-of-machine-learning-models-d4f1a9c7a9cf
  • https://towardsdatascience.com/deep-transfer-learning-for-image-classification-f3c7e0ec1a14
  • DenseNet: https://medium.com/the-advantages-of-densenet/the-advantages-of-densenet-98de3019cdac
  • https://medium.com/secure-and-private-ai-writing-challenge/data-augmentation-increases-accuracy-of-your-model-but-how-aa1913468722
Go Top
comments powered by Disqus